package com.andy.blog.common.utils.file;

import io.vavr.API;
import org.apache.commons.lang3.StringUtils;

import static io.vavr.API.$;
import static io.vavr.API.Case;

/**
 * 媒体类型工具类
 * Created by andy on 2023-04-05 11:38
 */
public class MimeTypeUtils {

    public static final String IMAGE_PNG = "image/png";

    public static final String IMAGE_JPG = "image/jpg";

    public static final String IMAGE_JPEG = "image/jpeg";

    public static final String IMAGE_BMP = "image/bmp";

    public static final String IMAGE_GIF = "image/gif";

    public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"};

    public static final String[] FLASH_EXTENSION = {"swf", "flv"};

    public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
            "asf", "rm", "rmvb"};

    public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb"};

    public static final String[] DEFAULT_ALLOWED_EXTENSION = {
            // 图片
            "bmp", "gif", "jpg", "jpeg", "png",
            // word excel powerpoint
            "doc", "docx", "xls", "xlsx", "ppt", "pptx", "html", "htm", "txt",
            // 压缩文件
            "rar", "zip", "gz", "bz2",
            // 视频格式
            "mp4", "avi", "rmvb",
            // pdf
            "pdf"};

    public static String getExtension(String prefix) {
        return API.Match(prefix).of(
                Case($(pre -> StringUtils.equals(pre, IMAGE_PNG)), value -> "png"),
                Case($(pre -> StringUtils.equals(pre, IMAGE_JPG)), value -> "jpg"),
                Case($(pre -> StringUtils.equals(pre, IMAGE_JPEG)), value -> "jpeg"),
                Case($(pre -> StringUtils.equals(pre, IMAGE_BMP)), value -> "bmp"),
                Case($(pre -> StringUtils.equals(pre, IMAGE_GIF)), value -> "gif"),
                Case($(), s -> null)
        );
    }

}
